package net.yeah.mickey_zhouyou.database.domain;

import java.util.Comparator;

import net.yeah.mickey_zhouyou.database.cache.SequenceCache;

/**
 * 所有实体类的公共超类。
 * 
 * @author Mickey
 * 
 */
public abstract class BaseEntity extends BaseTable implements
		Comparator<BaseEntity> {

	private long id;

	{
		// 所有实体对象创建时(非clone创建)自动分配ID
		id = SequenceCache.getNextId(this.getClass());
	}

	public long getId() {
		return id;
	}

	@Override
	public int compare(BaseEntity o1, BaseEntity o2) {
		if (o1.id > o2.id)
			return 1;
		if (o1.id < o2.id)
			return -1;
		return 0;
	}

}
